package com.pdemo.front.resource;

import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.annotation.JsonView;
import com.pdemo.core.entity.SystemAdmin;
import com.pdemo.core.entity.Views;
import com.pdemo.front.annotation.Authenticate;
import com.pdemo.front.service.AdminService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;

@Service
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Path("/admin")
@Api(value = "/admin", description = "Operations about System Admin")
@RolesAllowed("ROLE_ADMIN")
@Authenticate
public class AdminResource {
	
	
	@Autowired
	@Qualifier("adminService")
	AdminService adminService;
	
	@POST
	@Path("/admins")
	@ApiOperation(value="Create an admin", notes="need to input the mandatory attributes, and return the new created entity's id", response = Integer.class)
	@ApiResponses(value = { @ApiResponse(code = 200, message = "created successfully") })
	public Long createAdmin(@Context HttpServletRequest request, SystemAdmin admin){
		return adminService.createAdmin(admin);
	}
	
	@GET
	@Path("/admins")
	@JsonView(Views.Client.class)
	@ApiOperation(value = "Get all the system admins", notes = "Returns all the admins in the system", response = SystemAdmin.class)
	@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),@ApiResponse(code = 404, message = "Pet not found") })
	public List<SystemAdmin> getAdmins(){
		return adminService.getAllSystemAdmin();
	}
}
